package com.back.demo.controller;

import com.back.demo.common.CommonResult;
import com.back.demo.controller.myVO.adminVO.MoveClassVO;
import com.back.demo.controller.myVO.basicVO.ClassVO;
import com.back.demo.controller.myVO.basicVO.MajorVO;
import com.back.demo.controller.myVO.basicVO.MentorVO;
import com.back.demo.controller.myVO.adminVO.ConditionsVO;
import com.back.demo.controller.myVO.studentVO.ItemAdminVO;
import com.back.demo.controller.myVO.basicVO.StudentInformationVO;
import com.back.demo.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@Api(tags = "管理员功能")
@RestController
@RequestMapping("/server/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    // student
    // student
    // student
    @ApiOperation("导入学生名单")
    @PostMapping("/import-student-information")
    public CommonResult<?> importStudentInformation(@RequestHeader("Authorization") String authHeader, @RequestParam("file") MultipartFile file) throws IOException {
        String information = adminService.upload(file);
        if (information.equals("文件上传成功")) {
            information = adminService.importStudentInformation(file.getOriginalFilename());
            return CommonResult.success(information);
        }
        return CommonResult.error(50001, information);
    }

    @ApiOperation("手动新增/修改学生信息")
    @PostMapping("/submit-student-information")
    public CommonResult<?> submitStudentInformation(@RequestHeader("Authorization") String authHeader, @RequestBody StudentInformationVO studentInformationVO) {
        try {
            if (studentInformationVO.getUserId() == 0) { // 新增
                adminService.addStudentInformation(studentInformationVO);
            } else { // 修改
                adminService.modifyStudentInformation(studentInformationVO);
            }
            return CommonResult.success("操作成功");
        } catch (Exception e) {
            return CommonResult.error(50001, e.getMessage());
        }
    }

    @ApiOperation("统计学生个数的查询接口")
    @PostMapping("/count-student")
    public CommonResult<?> countStudent(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countStudent(conditionsVO));
    }

    @ApiOperation("学生个人信息的查询接口")
    @PostMapping("/acquire-student-information")
    public CommonResult<?> acquireStudentInformation(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<StudentInformationVO> listVO = adminService.acquireStudentInformation(conditionsVO);
        return CommonResult.success(listVO);
    }

    @ApiOperation("学生个人信息的查询接口")
    @GetMapping("/get-student-information/{userId}")
    public CommonResult<?> getStudentInformation(@RequestHeader("Authorization") String authHeader, @PathVariable Integer userId) {
        StudentInformationVO studentInformationVO = adminService.getStudentInformation(userId);
        return CommonResult.success(studentInformationVO);
    }
    // student
    // student
    // student

    // count
    // count
    // count
    @ApiOperation("统计论文成果个数的查询接口")
    @PostMapping("/count-paper")
    public CommonResult<?> countPaper(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countPaper(conditionsVO));
    }

    @ApiOperation("统计专利成果个数的查询接口")
    @PostMapping("/count-patent")
    public CommonResult<?> countPatent(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countPatent(conditionsVO));
    }

    @ApiOperation("统计比赛成果个数的查询接口")
    @PostMapping("/count-competition")
    public CommonResult<?> countCompetition(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countCompetition(conditionsVO));
    }

    @ApiOperation("统计软件著作权成果个数的查询接口")
    @PostMapping("/count-software-copyright")
    public CommonResult<?> countSoftwareCopyright(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countSoftwareCopyright(conditionsVO));
    }

    @ApiOperation("统计其它成果个数的查询接口")
    @PostMapping("/count-other")
    public CommonResult<?> countOther(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        return CommonResult.success(adminService.countOther(conditionsVO));
    }
    // count
    // count
    // count

    // acquire
    // acquire
    // acquire
    @ApiOperation("学生所有论文成果的查询接口")
    @PostMapping("/acquire-paper")
    public CommonResult<?> acquirePaper(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<ItemAdminVO> listVO = adminService.acquirePaper(conditionsVO);
        return CommonResult.success(listVO);
    }

    @ApiOperation("学生所有论文成果的查询接口")
    @PostMapping("/acquire-patent")
    public CommonResult<?> acquirePatent(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<ItemAdminVO> listVO = adminService.acquirePatent(conditionsVO);
        return CommonResult.success(listVO);
    }

    @ApiOperation("学生所有比赛成果的查询接口")
    @PostMapping("/acquire-competition")
    public CommonResult<?> acquireCompetition(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<ItemAdminVO> listVO = adminService.acquireCompetition(conditionsVO);
        return CommonResult.success(listVO);
    }

    @ApiOperation("学生所有比赛成果的查询接口")
    @PostMapping("/acquire-software-copyright")
    public CommonResult<?> acquireSoftwareCopyright(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<ItemAdminVO> listVO = adminService.acquireSoftwareCopyright(conditionsVO);
        return CommonResult.success(listVO);
    }

    @ApiOperation("学生所有其它成果的查询接口")
    @PostMapping("/acquire-other")
    public CommonResult<?> acquireOther(@RequestHeader("Authorization") String authHeader, @RequestBody ConditionsVO conditionsVO) {
        ArrayList<ItemAdminVO> listVO = adminService.acquireOther(conditionsVO);
        return CommonResult.success(listVO);
    }
    // acquire
    // acquire
    // acquire

    // find
    // find
    // find
    @ApiOperation("论文详情查找接口")
    @GetMapping("/find-paper-detail/{id}")
    public CommonResult<?> findPaperDetail(@RequestHeader("Authorization") String authHeader, @PathVariable Integer id) {
        try {
            return CommonResult.success(adminService.findPaperDetail(id));
        } catch (Exception e) {
            System.out.println(e.toString());
            return CommonResult.error(50003, "未能成功获取论文详情");
        }
    }

    @ApiOperation("专利详情查找接口")
    @GetMapping("/find-patent-detail/{id}")
    public CommonResult<?> findPatentDetail(@RequestHeader("Authorization") String authHeader, @PathVariable Integer id) {
        try {
            return CommonResult.success(adminService.findPatentDetail(id));
        } catch (Exception e) {
            System.out.println(e.toString());
            return CommonResult.error(50003, "未能成功获取专利详情");
        }
    }

    @ApiOperation("比赛详情查找接口")
    @GetMapping("/find-competition-detail/{id}")
    public CommonResult<?> findCompetitionDetail(@RequestHeader("Authorization") String authHeader, @PathVariable Integer id) {
        try {
            return CommonResult.success(adminService.findCompetitionDetail(id));
        } catch (Exception e) {
            System.out.println(e.toString());
            return CommonResult.error(50003, "未能成功获取专利详情");
        }
    }

    @ApiOperation("软件著作权详情查找接口")
    @GetMapping("/find-software-copyright-detail/{id}")
    public CommonResult<?> findSoftwareCopyrightDetail(@RequestHeader("Authorization") String authHeader, @PathVariable Integer id) {
        try {
            return CommonResult.success(adminService.findSoftwareCopyrightDetail(id));
        } catch (Exception e) {
            System.out.println(e.toString());
            return CommonResult.error(50003, "未能成功获取专利详情");
        }
    }

    @ApiOperation("其它详情查找接口")
    @GetMapping("/find-other-detail/{id}")
    public CommonResult<?> findOtherDetail(@RequestHeader("Authorization") String authHeader, @PathVariable Integer id) {
        try {
            return CommonResult.success(adminService.findOtherDetail(id));
        } catch (Exception e) {
            System.out.println(e.toString());
            return CommonResult.error(50003, "未能成功获取其它详情");
        }
    }
    // find
    // find
    // find

    // export
    // export
    // export
    @ApiOperation("导出论文成果")
    @PostMapping("/gather-paper")
    public CommonResult<?> gatherPaper(@RequestBody ConditionsVO conditionsVO) throws IOException {
//        System.out.println(System.getProperty("user.dir"));
//        System.out.println(conditionsVO);
        adminService.gatherPaper(conditionsVO);
        return CommonResult.success("导出成功");
    }

    @ApiOperation("导出专利成果")
    @PostMapping("/gather-patent")
    public CommonResult<?> gatherPatent(@RequestBody ConditionsVO conditionsVO) throws IOException {
//        System.out.println(System.getProperty("user.dir"));
//        System.out.println(conditionsVO);
        adminService.gatherPatent(conditionsVO);
        return CommonResult.success("导出成功");
    }

    @ApiOperation("导出比赛成果")
    @PostMapping("/gather-competition")
    public CommonResult<?> gatherCompetition(@RequestBody ConditionsVO conditionsVO) throws IOException {
//        System.out.println(System.getProperty("user.dir"));
//        System.out.println(conditionsVO);
        adminService.gatherCompetition(conditionsVO);
        return CommonResult.success("导出成功");
    }

    @ApiOperation("导出软件著作权成果")
    @PostMapping("/gather-software-copyright")
    public CommonResult<?> gatherSoftwareCopyright(@RequestBody ConditionsVO conditionsVO) throws IOException {
//        System.out.println(System.getProperty("user.dir"));
//        System.out.println(conditionsVO);
        adminService.gatherSoftwareCopyright(conditionsVO);
        return CommonResult.success("导出成功");
    }

    @ApiOperation("导出其它成果")
    @PostMapping("/gather-other")
    public CommonResult<?> gatherOther(@RequestBody ConditionsVO conditionsVO) throws IOException {
//        System.out.println(System.getProperty("user.dir"));
//        System.out.println(conditionsVO);
        adminService.gatherOther(conditionsVO);
        return CommonResult.success("导出成功");
    }

    @ApiOperation("下载")
    @GetMapping("/download")
    public void download(HttpServletResponse response, @RequestParam("filename") String fileName) throws IOException {
        adminService.download(response, fileName);
    }
    // export
    // export
    // export

    // major/class/mentor
    // major/class/mentor
    // major/class/mentor
    @ApiOperation("新增专业信息")
    @PostMapping("/add-major-information")
    public CommonResult<?> addMajorInformation(@RequestHeader("Authorization") String authHeader, @RequestBody MajorVO majorVO) {
        adminService.addMajorInformation(majorVO);
        return CommonResult.success("新增专业信息成功！");
    }

    @ApiOperation("修改专业信息")
    @PostMapping("/modify-major-information")
    public CommonResult<?> modifyMajorInformation(@RequestHeader("Authorization") String authHeader, @RequestBody MajorVO majorVO) {
        adminService.modifyMajorInformation(majorVO);
        return CommonResult.success("专业信息修改成功！");
    }

    @ApiOperation("删除专业信息")
    @DeleteMapping("/remove-major-information/{majorId}")
    public CommonResult<?> removeMajorInformation(@RequestHeader("Authorization") String authHeader, @PathVariable Integer majorId) {
        adminService.removeMajorInformation(majorId);
        return CommonResult.success("专业信息删除成功！");
    }

    @ApiOperation("新增班级信息")
    @PostMapping("/add-class-information")
    public CommonResult<?> addClassInformation(@RequestHeader("Authorization") String authHeader, @RequestBody ClassVO classVO) {
        adminService.addClassInformation(classVO);
        return CommonResult.success("新增班级信息成功！");
    }

    @ApiOperation("移动班级信息")
    @PostMapping("/move-class")
    public CommonResult<?> moveClass(@RequestHeader("Authorization") String authHeader, @RequestBody MoveClassVO moveClassVO) {
        adminService.moveClass(moveClassVO.getClassId1(), moveClassVO.getClassId2());
        return CommonResult.success("移动成功！");
    }

    @ApiOperation("修改班级信息")
    @PostMapping("/modify-class-information")
    public CommonResult<?> modifyClassInformation(@RequestHeader("Authorization") String authHeader, @RequestBody ClassVO classVO) {
        adminService.modifyClassInformation(classVO);
        return CommonResult.success("学苑信息修改成功！");
    }

    @ApiOperation("删除班级信息")
    @DeleteMapping("/remove-class-information/{classId}")
    public CommonResult<?> removeClassInformation(@RequestHeader("Authorization") String authHeader, @PathVariable Integer classId) {
        adminService.removeClassInformation(classId);
        return CommonResult.success("班级信息删除成功！");
    }

    @ApiOperation("新增导师信息")
    @PostMapping("/add-mentor-information")
    public CommonResult<?> addMentorInformation(@RequestHeader("Authorization") String authHeader, @RequestBody MentorVO mentorVO) {
        adminService.addMentorInformation(mentorVO);
        return CommonResult.success("新增导师信息成功！");
    }

    @ApiOperation("修改导师信息")
    @PostMapping("/modify-mentor-information")
    public CommonResult<?> modifyMentorInformation(@RequestHeader("Authorization") String authHeader, @RequestBody MentorVO mentorVO) {
        adminService.modifyMentorInformation(mentorVO);
        return CommonResult.success("导师信息修改成功！");
    }

    @ApiOperation("删除导师信息")
    @DeleteMapping("/remove-mentor-information/{mentorId}")
    public CommonResult<?> removeMentorInformation(@RequestHeader("Authorization") String authHeader, @PathVariable Integer mentorId) {
        adminService.removeMentorInformation(mentorId);
        return CommonResult.success("导师信息删除成功！");
    }
    // major/class/mentor
    // major/class/mentor
    // major/class/mentor
}
